package com.neu.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Schema(description = "二级需求实体")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("sfp") // 数据库表名
public class FpSecondDemand {

    @Schema(description = "关联的一级需求ID")
    private int fid;

    @Schema(description = "二级需求ID")
    @TableId(type = IdType.ASSIGN_ID) // 指定主键生成
    private int sid;

    @Schema(description = "二级需求名称")
    private String sname;

    @Schema(description = "二级需求描述")
    private String description;

    @Schema(description = "功能点类型")
    private String type;

    @Schema(description = "功能点类型数量")
    private int tnum;

    @Schema(description = "单个功能点未调整功能点数")
    private int ufp;

    @Schema(description = "复用度")
    private String degree;

    // 计算ufp的方法
    public void calufp() {
        int typeValue = 0;  // 用于保存对应的type值
        int degreeValue = 0; // 用于保存对应的degree值

        // 根据type值映射到ILF, EIF, EI, EO, EQ的数字
        switch (type) {
            case "1":
                typeValue = 1;
                break;
            case "2":
                typeValue = 2;
                break;
            case "3":
                typeValue = 3;
                break;
            case "4":
                typeValue = 4;
                break;
            case "5":
                typeValue = 5;
                break;
            default:
                throw new IllegalArgumentException("Invalid type value");
        }

        // 根据degree值映射到高、中、低的数字
        switch (degree) {
            case "1":
                degreeValue = 1; // 高
                break;
            case "2":
                degreeValue = 2; // 中
                break;
            case "3":
                degreeValue = 3; // 低
                break;
            default:
                throw new IllegalArgumentException("Invalid degree value");
        }

        // 使用复杂度表计算ufp
        int[][] complexityTable = {
                {7, 10, 15},  // ILF对应低、中、高的ufp
                {5, 7, 10},   // EIF对应低、中、高的ufp
                {3, 4, 6},    // EI对应低、中、高的ufp
                {4, 5, 7},    // EO对应低、中、高的ufp
                {3, 4, 6}     // EQ对应低、中、高的ufp
        };

        // 获取相应的ufp值
        this.ufp = complexityTable[typeValue - 1][degreeValue - 1];

    }

    public int getFid() {
        return fid;
    }

    public void setFid(int fid) {
        this.fid = fid;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getTnum() {
        return tnum;
    }

    public void setTnum(int tnum) {
        this.tnum = tnum;
    }

    public int getUfp() {
        return ufp;
    }

    public void setUfp(int ufp) {
        this.ufp = ufp;
    }

    public String getDegree() {
        return degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }
}
